package com.wantong.jianpu.activitys;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.lxj.xpopup.XPopup;
import com.wantong.jianpu.BR;
import com.wantong.jianpu.R;
import com.wantong.jianpu.base.BaseXActivity;
import com.wantong.jianpu.customviews.SelectImageView;
import com.wantong.jianpu.databinding.ActivityFaultProgressBinding;
import com.wantong.jianpu.viewmodels.FaultProViewModel;

import java.util.List;

/**
 * 维修进度
 */
public class FaultProgressActivity extends BaseXActivity<ActivityFaultProgressBinding, FaultProViewModel> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_fault_progress;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        setToolbar(binding.baseToolBar);
        viewModel.repairOrderId=getIntent().getExtras().getString("id");

        binding.selectImageView.setActivity(this);
        binding.selectImageView.setCallBack(new SelectImageView.SelectCallBack() {
            @Override
            public void selectImagePath(List<String> filePath) {
                viewModel.upLoadFile(filePath);
            }

            @Override
            public void deletePosition(int position) {
                if(viewModel.files.get(position)!=null){
                    viewModel.files.remove(position);
                }
            }
        });

        viewModel.stateDialogEvent.observe(this, strings -> {
            new XPopup.Builder(FaultProgressActivity.this)
                    .asBottomList("请选择维修状态", strings,
                            (position, text) -> {
                                viewModel.type.setValue(position);
                                viewModel.setState(text);
                            }).show();
        });
        viewModel.userDialogEvent.observe(this, strings -> {
            new XPopup.Builder(FaultProgressActivity.this)
                    .asBottomList("请选择协助人员", strings,
                            (position, text) -> {
                                viewModel.setUserPosition(position);
                            }).show();
        });

        viewModel.measuresDialogEvent.observe(this, strings -> {
            new XPopup.Builder(FaultProgressActivity.this)
                    .asBottomList("请选择故障分析", strings,
                            (position, text) -> {
                                viewModel.setMeasuresPosition(position);
                            }).show();
        });

        viewModel.repairDialogEvent.observe(this, strings -> {
            new XPopup.Builder(FaultProgressActivity.this)
                    .asBottomList("请选择维修方式", strings,
                            (position, text) -> {
                                viewModel.setRepairType(text);
                            }).show();
        });

        viewModel.natureDialogEvent.observe(this, strings -> {
            new XPopup.Builder(FaultProgressActivity.this)
                    .asBottomList("请选择维修性质", strings,
                            (position, text) -> {
                                viewModel.setNatureType(text);
                            }).show();
        });
    }
}